
$(document).ready(function(){
	$('#home .one_products:eq(3)').css('margin','20px 0 0 0');
	$('#home .one_products:eq(7)').css('margin','20px 0 0 0');
	$('#home .one_products:eq(12)').css('margin','20px 0 0 0');
	
	/*$('#page .one_products:eq(2)').css('margin','20px 0 0 0');
	$('#page .one_products:eq(5)').css('margin','20px 0 0 0');
	$('#page .one_products:eq(8)').css('margin','20px 0 0 0');
	$('#page .one_products:eq(11)').css('margin','20px 0 0 0');*/
	
	var count_products=$('#page .one_products').length;
	for(i=0;i<count_products;i++){
		if(i%3==2){
			$('#page .one_products:eq('+i+')').css('margin','20px 0 0 0');
			continue;	
		}
	}
	
	jQuery('#event .event_title:odd').addClass('addclass_promotion');
	jQuery('#event .event_content:gt(0)').hide();
	jQuery('#event .event_title').click(function(){
		var tmp=jQuery(this).next();
		if(tmp.is(':hidden') === true){
			$('.event_content article span a').show();
			$('.event_content article div').hide();
			jQuery('#event .event_content').slideUp();
			tmp.slideDown();
		}else{
			tmp.slideUp();
		}
	});
	
	if(!$('#show_pass').is(':checked')){
		$('#show_pass_new').hide();
	}
	
	$('#show_pass').bind('change', function () {
		if ($(this).is(':checked'))
			$('#show_pass_new').slideDown();
	    else
			$('#show_pass_new').slideUp();
	});
});

(function($) {
	$(function() {
		$("#scroller").simplyScroll({orientation:'vertical',customClass:'vert'});
	});
})(jQuery);

function EnterLogin(e){
	if(e.keyCode == 13){ 
		login();
	}
}

function EnterForgot(e){
	if(e.keyCode == 13){ 
		forgot();
	}
}

function showNew(id,obj){
	$('.event_content article span a').show();
	$('.show_content_'+id).slideDown();
	$(obj).hide();
}

function searchContent(start){
	$('#start').val(start);
	var per_page=$('#per_page').val();
	var show_category=$('#show_category').val();
	var id_category=$('#id_category').val();
	var idProfile=$('#idProfile').val();
	$.post(
		root+module+'/ajaxLoad',
		{
			start: start,
			per_page: per_page,
			show_category:show_category,
			id_category:id_category,
			idProfile:idProfile,
		},function(data){		
			$(window).scrollTop(90);
			$('#page').html(data);
			var count_products=$('#page .one_products').length;
			for(i=0;i<count_products;i++){
				if(i%3==2){
					$('#page .one_products:eq('+i+')').css('margin','20px 0 0 0');
					continue;	
				}
			}
			jq_cart();
		}
	)
}

function jq_cart(){
	var hideenCart=$('#hiddenCart').val();
	$("#basketItemsWrap li:first").hide();

	$(".custom_cart a").click(function() {
		var productIDValSplitter 	= (this.id).split("_");
		var productIDVal 			= productIDValSplitter[1];
		
		var productX 		= $("#productImageWrapID_" + productIDVal).offset().left;
		var productY 		= $("#productImageWrapID_" + productIDVal).offset().top;
		
		if( $("#productID_" + productIDVal).length > 0){
			var basketX 		= $("#productID_" + productIDVal).offset().left;
			var basketY 		= $("#productID_" + productIDVal).offset().top;			
		} else {
			if(!hideenCart){
				var basketX 		= $("#basketTitleWrap").offset().left;
				var basketY 		= $("#basketTitleWrap").offset().top;
			}else{
				var basketX 		= $("#CartProducts").offset().left;
				var basketY 		= $("#CartProducts").offset().top;
			}
		}
		
		var gotoX 			= basketX - productX;
		var gotoY 			= basketY - productY;
		
		var newImageWidth 	= $("#productImageWrapID_" + productIDVal).width() / 4;
		var newImageHeight	= $("#productImageWrapID_" + productIDVal).height() / 4;
		
		$("#productImageWrapID_" + productIDVal)
		.clone()
		.prependTo("#productImageWrapID_" + productIDVal)
		.css({'position' : 'absolute','z-index':'9999'})
		.animate({opacity: 0.6}, 100 )
		.animate({opacity: 0.2, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {
																																																																										  			$(this).remove();
		
			/*$.ajax({  
				type: "POST",  
				url: "inc/functions.php",  
				data: { productID: productIDVal, action: "addToBasket"},  
				success: function(theResponse) {
					
					if( $("#productID_" + productIDVal).length > 0){
						$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						$("#productID_" + productIDVal).before(theResponse).remove();
						$("#productID_" + productIDVal).animate({ opacity: 0 }, 500);
						$("#productID_" + productIDVal).animate({ opacity: 1 }, 500);
						$("#notificationsLoader").empty();
						
					} else {
						$("#basketItemsWrap li:first").before(theResponse);
						$("#basketItemsWrap li:first").hide();
						$("#basketItemsWrap li:first").show("slow");  
						$("#notificationsLoader").empty();			
					}
					
				}  
			}); */ 
		
		});
		
	});	
}

function enterSearch(e){
	if (e.keyCode == 13){ 
		searchContent(0);
	}
}

function searchProducts(start,per_page){
	var per_page=$('#per_page').val();
	var keySearch=$('#keySearch').val();
	var ajaxSearchPro=$('#ajaxSearchPro').val();
	$('#start').val(start);
	if(ajaxSearchPro){
		var linkSearch=root+'products/searchProductsAjax';
	}else{
		var linkSearch=root+'products/searchProducts';
	}
	
	$.post(linkSearch,{
		start: start,
		per_page: per_page,
		keySearch:keySearch,
	},function(data){
		if(!ajaxSearchPro){				
			$('body').html(data);
			$('#keySearch').val(keySearch);	
			var count_products=$('#page .one_products').length;
			for(i=0;i<count_products;i++){
				if(i%3==2){
					$('#page .one_products:eq('+i+')').css('margin','20px 0 0 0');
					continue;	
				}
			}
			jq_cart();			
		}else{
			$('#page').html(data);
			var count_products=$('#page .one_products').length;
			for(i=0;i<count_products;i++){
				if(i%3==2){
					$('#page .one_products:eq('+i+')').css('margin','20px 0 0 0');
					continue;	
				}
			}
			jq_cart();
		}
	});
}
